import { FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table';
import { formatToDateTime } from '/@/utils/dateUtil';
import { PageLadleInputDto, LadlesServiceProxy, IdInput } from '/@/services/ServiceProxies';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();

export const searchFormSchema: FormSchema[] = [
    {
        field: 'filter',
        label: t('common.key'),
        component: 'Input',
        colProps: { span: 8 },
    },
];

export const tableColumns: BasicColumn[] = [
    {
        title: t('routes.asset.ladle.code'),
        dataIndex: 'ladleCode',
    },
    {
        title: t('routes.asset.ladle.rfid'),
        dataIndex: 'rfid',
    },
    {
        title: t('routes.asset.ladle.name'),
        dataIndex: 'ladleName',
    },
    {
        title: t('common.description'),
        dataIndex: 'description',
    },
    {
        title: t('routes.asset.ladle.skinWeight'),
        dataIndex: 'skinWeight',
    },
    {
        title: t('routes.asset.ladle.material'),
        dataIndex: 'material',
    },
    {
        title: t('routes.asset.ladle.active'),
        dataIndex: 'active',
    },
    {
        title: t('common.creator'),
        dataIndex: 'creatorName',
    },
    {
        title: t('common.creationTime'),
        dataIndex: 'creationTime',
        customRender: ({ text }) => {
            return formatToDateTime(text);
        }
    },
    {
        title: t('common.lastModifier'),
        dataIndex: 'LastModifierName',
    },
    {
        title: t('common.lastModificationTime'),
        dataIndex: 'lastModificationTime',
        customRender: ({ text }) => {
            return formatToDateTime(text);
        }
    }
];

export const createFormSchema: FormSchema[] = [
    {
        field: 'ladleCode',
        label: t('routes.asset.ladle.code'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'rfid',
        label: t('routes.asset.ladle.rfid'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'ladleName',
        label: t('routes.asset.ladle.name'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'skinWeight',
        label: t('routes.asset.ladle.skinWeight'),
        component: 'InputNumber',
        required: true,
        colProps: { span: 18 },
        componentProps:{
            min:0,
            step:0.1
        }
    },
    {
        field: 'material',
        label: t('routes.asset.ladle.material'),
        component: 'Select',
        required: true,
        colProps: { span: 18 },
        componentProps: {
            options: [
                {
                    label: t('routes.asset.ladle.material_highAlumina'),
                    value: 0,
                    key: '0',
                },
                {
                    label: t('routes.asset.ladle.material_aluminumMagnesiumCarbon'),
                    value: 1,
                    key: '1',
                },
                {
                    label: t('routes.asset.ladle.material_magnesiumCarbon'),
                    value: 2,
                    key: '2',
                }
            ],
        }
    },
    {
        field: 'active',
        component: 'RadioGroup',
        required: true,
        label: t('routes.asset.ladle.active'),
        colProps: {
            span: 18,
        },
        componentProps: {
            options: [
                {
                    label: t('common.true'),
                    value: true,
                },
                {
                    label: t('common.false'),
                    value: false,
                },
            ],
        },
    },
    {
        field: 'description',
        label: t('common.description'),
        component: 'InputTextArea',
        required: false,
        colProps: { span: 24 },
    }
];

export const updateFormSchema: FormSchema[] = [
    {
        field: 'id',
        label: 'Id',
        component: 'Input',
        ifShow: false,
        colProps: { span: 18 },
    },
    {
        field: 'ladleCode',
        label: t('routes.asset.ladle.code'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'rfid',
        label: t('routes.asset.ladle.rfid'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'ladleName',
        label: t('routes.asset.ladle.name'),
        component: 'Input',
        required: true,
        colProps: { span: 18 },
    },
    {
        field: 'skinWeight',
        label: t('routes.asset.ladle.skinWeight'),
        component: 'InputNumber',
        required: true,
        colProps: { span: 18 },
        componentProps:{
            min:0,
            step:0.1
        }
    },
    {
        field: 'material',
        label: t('routes.asset.ladle.material'),
        component: 'Select',
        required: true,
        colProps: { span: 18 },
        componentProps: {
            options: [
                {
                    label: t('routes.asset.ladle.material_highAlumina'),
                    value: 0,
                    key: '0',
                },
                {
                    label: t('routes.asset.ladle.material_aluminumMagnesiumCarbon'),
                    value: 1,
                    key: '1',
                },
                {
                    label: t('routes.asset.ladle.material_magnesiumCarbon'),
                    value: 2,
                    key: '2',
                }
            ],
        }
    },
    {
        field: 'active',
        component: 'RadioGroup',
        required: true,
        label: t('routes.asset.ladle.active'),
        colProps: {
            span: 18,
        },
        componentProps: {
            options: [
                {
                    label: t('common.true'),
                    value: true,
                },
                {
                    label: t('common.false'),
                    value: false,
                },
            ],
        },
    },
    {
        field: 'description',
        label: t('common.description'),
        component: 'InputTextArea',
        required: false,
        colProps: { span: 24 },
    }
];

export async function createAsync({ params }) {
    const ladlesServiceProxy = new LadlesServiceProxy();
    await ladlesServiceProxy.create(params);
}

export async function updateAsync({ params }) {
    const ladlesServiceProxy = new LadlesServiceProxy();
    await ladlesServiceProxy.edit(params);
}

export async function deleteAsync({ id }) {
    const ladlesServiceProxy = new LadlesServiceProxy();
    const request = new IdInput();
    request.id = id;
    await ladlesServiceProxy.delete(request);
}

export async function getTableListAsync(params: PageLadleInputDto) {
    const ladlesServiceProxy = new LadlesServiceProxy();
    return ladlesServiceProxy.page(params);
}